package cn.zjutleo.village_server.service;

import cn.zjutleo.village_server.dto.AccurateSupportApplyDto;
import cn.zjutleo.village_server.dto.AccurateSupportSurveyDto;
import cn.zjutleo.village_server.entity.AccurateSupportApply;
import cn.zjutleo.village_server.entity.AccurateSupportSurvey;
import cn.zjutleo.village_server.mapper.AccurateSupportApplyMapper;
import cn.zjutleo.village_server.mapper.AccurateSupportSurveyMapper;
import cn.zjutleo.village_server.service.converter.AccurateSupportConverter;
import cn.zjutleo.village_server.service.converter.AccurateSupportSurveyConverter;
import cn.zjutleo.village_server.vo.AccurateSupportApplyDetailVo;
import cn.zjutleo.village_server.vo.AccurateSupportApplyRoughVo;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.sql.Timestamp;
import java.util.List;

/**
 * @author : Qin Zhenghan
 * @date : Created in 2021/10/2
 * @description: 精准帮扶相关业务类
 */
@Service
public class AccurateSupportService {

    @Resource
    private AccurateSupportApplyMapper accurateSupportApplyMapper;

    @Resource
    private AccurateSupportSurveyMapper accurateSupportSurveyMapper;

    /**
     * 村民精准帮扶申报
     *
     * @param accurateSupportApplyDto 精准帮扶申报DTO
     * @param userId 用户id
     */
    public void applyForAccurateSupport(AccurateSupportApplyDto accurateSupportApplyDto, Integer userId) {
        AccurateSupportApply accurateSupportApply = AccurateSupportConverter.INSTANCES.dtoToEntity(accurateSupportApplyDto);
        accurateSupportApply.setUserId(userId);
        accurateSupportApply.setApplyTime(new Timestamp(System.currentTimeMillis()));
        accurateSupportApplyMapper.insertSelective(accurateSupportApply);
    }

    /**
     * 获取精准帮扶粗略信息列表
     *
     * @return 精准帮扶申请粗略信息列表
     */
    public List<AccurateSupportApplyRoughVo> getAccurateSupportApplyRoughVos() {
        List<AccurateSupportApplyRoughVo> list = accurateSupportApplyMapper.selectRoughVos();
        return list;
    }

    /**
     * 根据申请表id获取精准帮扶申请详细信息
     *
     * @param applyId 申请表id
     * @return 精准帮扶申请详细信息
     */
    public AccurateSupportApplyDetailVo getAccurateSupportApplyDetailVo(Integer applyId) {
        return accurateSupportApplyMapper.selectDetailVoByPrimaryKey(applyId);
    }

    /**
     * 上传精准帮扶走访报告
     *
     * @param accurateSupportSurveyDto 精准帮扶走访上报DTO
     */
    public void addAccurateSupportSurvey(AccurateSupportSurveyDto accurateSupportSurveyDto) {
        AccurateSupportSurvey accurateSupportSurvey = AccurateSupportSurveyConverter.INSTANCES.dtoToEntity(accurateSupportSurveyDto);
        accurateSupportSurvey.setTime(new Timestamp(System.currentTimeMillis()));
        accurateSupportSurveyMapper.insertSelective(accurateSupportSurvey);
    }

}
